/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package apus.action.person;

import apus.action.Action;
import apus.action.ActionResult;
import apus.entity.Person;
import apus.exception.EntityNotFoundException;
import apus.persistence.PersonDAO;
import apus.services.ServiceLocator;
import java.util.ArrayList;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author 21vek
 */
public class PersonSearchAction implements Action{

    @Override
    public String getName() {
        return "person.search";
    }

    @Override
    public ActionResult execute(HttpServletRequest request, HttpServletResponse response) {
                List <Person> personList;
        try {
            personList = ServiceLocator.getService(PersonDAO.class).readByName(request.getParameter("name"),0);
        } catch (EntityNotFoundException e) {
            personList = new ArrayList<Person>();
        }
        //request.setAttribute("searchQuery", request.getParameter("name"));
        request.setAttribute("personList", personList);
        return ActionResult.forward("/WEB-INF/View/search/personSearch.jsp");
    }
    
}
